package cn.hfuu.controller;

import cn.hfuu.domain.BaseDict;
import cn.hfuu.service.BaseDictService;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONArray;
import org.apache.struts2.ServletActionContext;

import java.util.List;

public class BaseDictAction extends ActionSupport {

    private String dict_type_code;
    private BaseDictService baseDictService;

    public String execute() throws Exception {
        //直接调用service层方法用获得的dcit_type_code查询加载项的List对象
        List<BaseDict> list  = baseDictService.getListByCode(dict_type_code);

        //将查询到的list对象转化为json格式的数据
        String json =  JSONArray.fromObject(list).toString();


        //将数据写给浏览器, 处理乱码问题
        ServletActionContext.getResponse().setContentType("application/json;charset=utf-8");
        ServletActionContext.getResponse().getWriter().write(json);

        //返回值设置为null，表示对结果不进行自动处理，手动处理
        return null;
    }

    public String getDict_type_code() {
        return dict_type_code;
    }

    public void setDict_type_code(String dict_type_code) {
        this.dict_type_code = dict_type_code;
    }

    public void setBaseDictService(BaseDictService baseDictService) {
        this.baseDictService = baseDictService;
    }
}
